using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWAZSAB
    {
        public DataRow Convert2WAZSAB(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWAZSAB(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WAZMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WAZKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WAZWSZS01"] = " ".PadRight(2 ); 
         dwReturn["WAZWSPROZ01"] = " ".PadRight(3 ); 
         dwReturn["WAZWSZS02"] = " ".PadRight(2 ); 
         dwReturn["WAZWSPROZ02"] = " ".PadRight(3 ); 
         dwReturn["WAZWSZS03"] = " ".PadRight(2 ); 
         dwReturn["WAZWSPROZ03"] = " ".PadRight(3 ); 
         dwReturn["WAZWSZS04"] = " ".PadRight(2 ); 
         dwReturn["WAZWSPROZ04"] = " ".PadRight(3 ); 
         dwReturn["WAZWSZS05"] = " ".PadRight(2 ); 
         dwReturn["WAZWSPROZ05"] = " ".PadRight(3 ); 
         dwReturn["WAZWSZS06"] = " ".PadRight(2 ); 
         dwReturn["WAZWSPROZ06"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG01"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS01"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ01"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG02"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS02"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ02"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG03"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS03"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ03"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG04"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS04"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ04"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG05"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS05"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ05"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG06"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS06"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ06"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG07"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS07"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ07"] = " ".PadRight(3 ); 
         dwReturn["WAZASANZTG08"] = " ".PadRight(0 ); 
         dwReturn["WAZASZS08"] = " ".PadRight(2 ); 
         dwReturn["WAZASPROZ08"] = " ".PadRight(3 ); 
         dwReturn["WAZKRMTR"] = " ".PadRight(0 ); 
         dwReturn["WAZKRZS"] = " ".PadRight(2 ); 
         dwReturn["WAZKRPROZ"] = " ".PadRight(3 ); 
         dwReturn["WAZAKOLPROZ"] = " ".PadRight(3 ); 
         dwReturn["WAZABVKPROZ"] = " ".PadRight(3 ); 
         dwReturn["WAZNEUB"] = " ".PadRight(8 ); 
         dwReturn["WAZNEUD"] = " ".PadRight(0 ); 
         dwReturn["WAZAENB"] = " ".PadRight(8 ); 
         dwReturn["WAZAEND"] = " ".PadRight(0 ); 
         dwReturn["WAZAENZL"] = " ".PadRight(0 ); 
         dwReturn["WAZMIZS"] = " ".PadRight(2 ); 
         dwReturn["WAZMIPROZ"] = " ".PadRight(3 ); 
         dwReturn["WAZRWTG1"] = " ".PadRight(0 ); 
         dwReturn["WAZRWTG2"] = " ".PadRight(0 ); 
         dwReturn["WAZRWTG3"] = " ".PadRight(0 ); 
         dwReturn["WAZRWPROZ1"] = " ".PadRight(3 ); 
         dwReturn["WAZRWPROZ2"] = " ".PadRight(3 ); 
         dwReturn["WAZRWPROZ3"] = " ".PadRight(3 ); 
         dwReturn["WAZFREI"] = " ".PadRight(143 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWAZSAB(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWAZSAB(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWAZSAB(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWAZSAB(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWAZSAB(dwLocal, ITXDBVERSION);
            }
            UpdateWAZSAB(dwLocal);
        }
        public void InsertWAZSAB(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WAZSAB(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWAZSAB(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WAZSAB WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WAZSAB  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WAZSAB";
            Return = Result;
            return Return;
        }
        public void DeleteWAZSAB(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WAZSAB   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWAZSAB(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WAZSAB SET "
                    +"WAZMANDANT= :WAZMANDANT,"
                    +"WAZKUNDNR= :WAZKUNDNR,"
                    +"WAZWSZS01= :WAZWSZS01,"
                    +"WAZWSPROZ01= :WAZWSPROZ01,"
                    +"WAZWSZS02= :WAZWSZS02,"
                    +"WAZWSPROZ02= :WAZWSPROZ02,"
                    +"WAZWSZS03= :WAZWSZS03,"
                    +"WAZWSPROZ03= :WAZWSPROZ03,"
                    +"WAZWSZS04= :WAZWSZS04,"
                    +"WAZWSPROZ04= :WAZWSPROZ04,"
                    +"WAZWSZS05= :WAZWSZS05,"
                    +"WAZWSPROZ05= :WAZWSPROZ05,"
                    +"WAZWSZS06= :WAZWSZS06,"
                    +"WAZWSPROZ06= :WAZWSPROZ06,"
                    +"WAZASANZTG01= :WAZASANZTG01,"
                    +"WAZASZS01= :WAZASZS01,"
                    +"WAZASPROZ01= :WAZASPROZ01,"
                    +"WAZASANZTG02= :WAZASANZTG02,"
                    +"WAZASZS02= :WAZASZS02,"
                    +"WAZASPROZ02= :WAZASPROZ02,"
                    +"WAZASANZTG03= :WAZASANZTG03,"
                    +"WAZASZS03= :WAZASZS03,"
                    +"WAZASPROZ03= :WAZASPROZ03,"
                    +"WAZASANZTG04= :WAZASANZTG04,"
                    +"WAZASZS04= :WAZASZS04,"
                    +"WAZASPROZ04= :WAZASPROZ04,"
                    +"WAZASANZTG05= :WAZASANZTG05,"
                    +"WAZASZS05= :WAZASZS05,"
                    +"WAZASPROZ05= :WAZASPROZ05,"
                    +"WAZASANZTG06= :WAZASANZTG06,"
                    +"WAZASZS06= :WAZASZS06,"
                    +"WAZASPROZ06= :WAZASPROZ06,"
                    +"WAZASANZTG07= :WAZASANZTG07,"
                    +"WAZASZS07= :WAZASZS07,"
                    +"WAZASPROZ07= :WAZASPROZ07,"
                    +"WAZASANZTG08= :WAZASANZTG08,"
                    +"WAZASZS08= :WAZASZS08,"
                    +"WAZASPROZ08= :WAZASPROZ08,"
                    +"WAZKRMTR= :WAZKRMTR,"
                    +"WAZKRZS= :WAZKRZS,"
                    +"WAZKRPROZ= :WAZKRPROZ,"
                    +"WAZAKOLPROZ= :WAZAKOLPROZ,"
                    +"WAZABVKPROZ= :WAZABVKPROZ,"
                    +"WAZNEUB= :WAZNEUB,"
                    +"WAZNEUD= :WAZNEUD,"
                    +"WAZAENB= :WAZAENB,"
                    +"WAZAEND= :WAZAEND,"
                    +"WAZAENZL= :WAZAENZL,"
                    +"WAZMIZS= :WAZMIZS,"
                    +"WAZMIPROZ= :WAZMIPROZ,"
                    +"WAZRWTG1= :WAZRWTG1,"
                    +"WAZRWTG2= :WAZRWTG2,"
                    +"WAZRWTG3= :WAZRWTG3,"
                    +"WAZRWPROZ1= :WAZRWPROZ1,"
                    +"WAZRWPROZ2= :WAZRWPROZ2,"
                    +"WAZRWPROZ3= :WAZRWPROZ3,"
                    +"WAZFREI= :WAZFREI,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WAZMANDANT", OracleType.NVarChar).Value = dwData["WAZMANDANT"].ToString(); 
          or1.Parameters.Add("WAZKUNDNR", OracleType.NVarChar).Value = dwData["WAZKUNDNR"].ToString(); 
          or1.Parameters.Add("WAZWSZS01", OracleType.NVarChar).Value = dwData["WAZWSZS01"].ToString(); 
          or1.Parameters.Add("WAZWSPROZ01", OracleType.NVarChar).Value = dwData["WAZWSPROZ01"].ToString(); 
          or1.Parameters.Add("WAZWSZS02", OracleType.NVarChar).Value = dwData["WAZWSZS02"].ToString(); 
          or1.Parameters.Add("WAZWSPROZ02", OracleType.NVarChar).Value = dwData["WAZWSPROZ02"].ToString(); 
          or1.Parameters.Add("WAZWSZS03", OracleType.NVarChar).Value = dwData["WAZWSZS03"].ToString(); 
          or1.Parameters.Add("WAZWSPROZ03", OracleType.NVarChar).Value = dwData["WAZWSPROZ03"].ToString(); 
          or1.Parameters.Add("WAZWSZS04", OracleType.NVarChar).Value = dwData["WAZWSZS04"].ToString(); 
          or1.Parameters.Add("WAZWSPROZ04", OracleType.NVarChar).Value = dwData["WAZWSPROZ04"].ToString(); 
          or1.Parameters.Add("WAZWSZS05", OracleType.NVarChar).Value = dwData["WAZWSZS05"].ToString(); 
          or1.Parameters.Add("WAZWSPROZ05", OracleType.NVarChar).Value = dwData["WAZWSPROZ05"].ToString(); 
          or1.Parameters.Add("WAZWSZS06", OracleType.NVarChar).Value = dwData["WAZWSZS06"].ToString(); 
          or1.Parameters.Add("WAZWSPROZ06", OracleType.NVarChar).Value = dwData["WAZWSPROZ06"].ToString(); 
          or1.Parameters.Add("WAZASANZTG01", OracleType.NVarChar).Value = dwData["WAZASANZTG01"].ToString(); 
          or1.Parameters.Add("WAZASZS01", OracleType.NVarChar).Value = dwData["WAZASZS01"].ToString(); 
          or1.Parameters.Add("WAZASPROZ01", OracleType.NVarChar).Value = dwData["WAZASPROZ01"].ToString(); 
          or1.Parameters.Add("WAZASANZTG02", OracleType.NVarChar).Value = dwData["WAZASANZTG02"].ToString(); 
          or1.Parameters.Add("WAZASZS02", OracleType.NVarChar).Value = dwData["WAZASZS02"].ToString(); 
          or1.Parameters.Add("WAZASPROZ02", OracleType.NVarChar).Value = dwData["WAZASPROZ02"].ToString(); 
          or1.Parameters.Add("WAZASANZTG03", OracleType.NVarChar).Value = dwData["WAZASANZTG03"].ToString(); 
          or1.Parameters.Add("WAZASZS03", OracleType.NVarChar).Value = dwData["WAZASZS03"].ToString(); 
          or1.Parameters.Add("WAZASPROZ03", OracleType.NVarChar).Value = dwData["WAZASPROZ03"].ToString(); 
          or1.Parameters.Add("WAZASANZTG04", OracleType.NVarChar).Value = dwData["WAZASANZTG04"].ToString(); 
          or1.Parameters.Add("WAZASZS04", OracleType.NVarChar).Value = dwData["WAZASZS04"].ToString(); 
          or1.Parameters.Add("WAZASPROZ04", OracleType.NVarChar).Value = dwData["WAZASPROZ04"].ToString(); 
          or1.Parameters.Add("WAZASANZTG05", OracleType.NVarChar).Value = dwData["WAZASANZTG05"].ToString(); 
          or1.Parameters.Add("WAZASZS05", OracleType.NVarChar).Value = dwData["WAZASZS05"].ToString(); 
          or1.Parameters.Add("WAZASPROZ05", OracleType.NVarChar).Value = dwData["WAZASPROZ05"].ToString(); 
          or1.Parameters.Add("WAZASANZTG06", OracleType.NVarChar).Value = dwData["WAZASANZTG06"].ToString(); 
          or1.Parameters.Add("WAZASZS06", OracleType.NVarChar).Value = dwData["WAZASZS06"].ToString(); 
          or1.Parameters.Add("WAZASPROZ06", OracleType.NVarChar).Value = dwData["WAZASPROZ06"].ToString(); 
          or1.Parameters.Add("WAZASANZTG07", OracleType.NVarChar).Value = dwData["WAZASANZTG07"].ToString(); 
          or1.Parameters.Add("WAZASZS07", OracleType.NVarChar).Value = dwData["WAZASZS07"].ToString(); 
          or1.Parameters.Add("WAZASPROZ07", OracleType.NVarChar).Value = dwData["WAZASPROZ07"].ToString(); 
          or1.Parameters.Add("WAZASANZTG08", OracleType.NVarChar).Value = dwData["WAZASANZTG08"].ToString(); 
          or1.Parameters.Add("WAZASZS08", OracleType.NVarChar).Value = dwData["WAZASZS08"].ToString(); 
          or1.Parameters.Add("WAZASPROZ08", OracleType.NVarChar).Value = dwData["WAZASPROZ08"].ToString(); 
          or1.Parameters.Add("WAZKRMTR", OracleType.NVarChar).Value = dwData["WAZKRMTR"].ToString(); 
          or1.Parameters.Add("WAZKRZS", OracleType.NVarChar).Value = dwData["WAZKRZS"].ToString(); 
          or1.Parameters.Add("WAZKRPROZ", OracleType.NVarChar).Value = dwData["WAZKRPROZ"].ToString(); 
          or1.Parameters.Add("WAZAKOLPROZ", OracleType.NVarChar).Value = dwData["WAZAKOLPROZ"].ToString(); 
          or1.Parameters.Add("WAZABVKPROZ", OracleType.NVarChar).Value = dwData["WAZABVKPROZ"].ToString(); 
          or1.Parameters.Add("WAZNEUB", OracleType.NVarChar).Value = dwData["WAZNEUB"].ToString(); 
          or1.Parameters.Add("WAZNEUD", OracleType.NVarChar).Value = dwData["WAZNEUD"].ToString(); 
          or1.Parameters.Add("WAZAENB", OracleType.NVarChar).Value = dwData["WAZAENB"].ToString(); 
          or1.Parameters.Add("WAZAEND", OracleType.NVarChar).Value = dwData["WAZAEND"].ToString(); 
          or1.Parameters.Add("WAZAENZL", OracleType.NVarChar).Value = dwData["WAZAENZL"].ToString(); 
          or1.Parameters.Add("WAZMIZS", OracleType.NVarChar).Value = dwData["WAZMIZS"].ToString(); 
          or1.Parameters.Add("WAZMIPROZ", OracleType.NVarChar).Value = dwData["WAZMIPROZ"].ToString(); 
          or1.Parameters.Add("WAZRWTG1", OracleType.NVarChar).Value = dwData["WAZRWTG1"].ToString(); 
          or1.Parameters.Add("WAZRWTG2", OracleType.NVarChar).Value = dwData["WAZRWTG2"].ToString(); 
          or1.Parameters.Add("WAZRWTG3", OracleType.NVarChar).Value = dwData["WAZRWTG3"].ToString(); 
          or1.Parameters.Add("WAZRWPROZ1", OracleType.NVarChar).Value = dwData["WAZRWPROZ1"].ToString(); 
          or1.Parameters.Add("WAZRWPROZ2", OracleType.NVarChar).Value = dwData["WAZRWPROZ2"].ToString(); 
          or1.Parameters.Add("WAZRWPROZ3", OracleType.NVarChar).Value = dwData["WAZRWPROZ3"].ToString(); 
          or1.Parameters.Add("WAZFREI", OracleType.NVarChar).Value = dwData["WAZFREI"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
